from rest_framework.viewsets import ModelViewSet
from meiduo_mall_admin.my_paginate import MyPageNumberPagination
from . import spec_option_serializers
from goods.models import SpecificationOption, SPUSpecification
from rest_framework.generics import ListAPIView



# spec_option选项表
class SpecOptionViewSet(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = spec_option_serializers.SpecOptionSerializer
    queryset = SpecificationOption.objects.all()


# 新增页面的规格选项
class OptionViewSet(ListAPIView):
    serializer_class = spec_option_serializers.OptionViewSerializer
    # queryset = SPUSpecification.objects.all()

    def get_queryset(self):
        queryset = SPUSpecification.objects.all()
        for spec in queryset:
            spec.name = "{}-{}".format(spec.spu.name, spec.name)

        return queryset
